<!DOCTYPE html>
<html>

	<head lang="en">
		<meta charset="UTF-8">
		<title>注册</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="format-detection" content="telephone=no">
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />

		<link rel="stylesheet" href="static/css/amazeui.css" />
		<link href="static/css/dlstyle.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" href="static/css/bootstrap.min.css" />
	</head>

	<body>
	
		<div class="login-boxtitle" style="height: 100px;">
			<div class="logoBig">
				<img src="static/images/logo.png" style="margin-left: 0px ; height: 100px;">
			</div>
		</div>

		<div class="login-banner" style="background: rgb(142,213,21);">
			<div class="login-main">
				<div class="login-banner-bg"><span></span><img width="400"  src="static/images/act2.png" /></div>
				
				<div class="login-box" id="container">
					<h3 class="title">用户注册</h3>
					<h5 :style="colorStyle">&nbsp;{{tips}}</h5>
					<div class="clear"></div>
					<div class="login-form" style="background: none;">
						<form>
							<div class="user-name">
								<label for="user"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></label>
								<input type="text" v-model="username"  placeholder="邮箱/手机/用户名" @keyup="checkRegistUserName">
								<br/>
							</div>
							
							<div class="user-pass" style="margin-top: 15px;">
								<label for="password"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span></label>
								<input type="password" v-model="password"  placeholder="请输入密码"  @keyup="checkRegistPassword">
							</div>
							<div class="user-pass" style="margin-top: 15px;">
								<label for="password"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span></label>
								<input type="password" v-model="repassword"  placeholder="请再次输入密码" @keyup="checkRegistRePassword">
							</div>
						</form>
					</div>
					<div class="login-links"><br /></div>
					<div class="am-cf">
						<input type="button" @click="doRegist" value="提交注册" class="am-btn am-btn-primary am-btn-sm">
					</div>
					<div class="partner"></div>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="static/js/vue.js" ></script>
		<script type="text/javascript" src="static/js/axios.min.js" ></script>
		<script type="text/javascript">
			var baseUrl="http://127.0.01:8080/haitaobao";
			var vm=new Vue({
				el:"#container",
				data:{
					tips:"",
					username:"",
					password:"",
					repassword:"",
					colorStyle:"",
					isRight:false,
				},
				methods:{
					doRegist:function(){
						if(isRight){
							axios.post(baseUrl+"/user/regist",{
								username:vm.username,
								password:vm.password,
							}).then((res)=>{
								if(res.data.code==200){
									vm.tips="注册成功";
									vm.colorStyle="color:green";
									setTimeout(function(){
										window.location.href="login.html";
									},1000);
								}else{
									vm.tips="注册失败";
									vm.colorStyle="color:red";
								}
							})
						}else{
							vm.tips="请输入账号和密码";
							vm.colorStyle="color:red";
						}
						
					},
					checkRegistUserName:function(){
						/* 先检验账号 */
						if(vm.username.length==0){
							vm.tips="账号不能为空";
							vm.colorStyle="color:red";
							vm.isRight=false;
						}else if(vm.username.length<8||vm.username.length>20){
							vm.tips="账号的长度必须大于8小于20";
							vm.colorStyle="color:red";
							vm.isRight=false;
						}else{
							vm.tips="";
						}
					},
					checkRegistPassword:function(){
						/* 检验密码 */
						if(vm.password.length==0){
							vm.tips="密码不能为空";
							vm.colorStyle="color:red";
							vm.isRight=false;
						}else if(vm.password.length<8||vm.password.length>20){
							vm.tips="密码的长度必须大于8小于20";
							vm.colorStyle="color:red";
							vm.isRight=false;
						}else{
							vm.tips="";
						}
					},
					checkRegistRePassword:function(){
						if(vm.repassword.length==0){
							vm.tips="请再次输入密码";
							vm.colorStyle="color:red";
							vm.isRight=false;
						}else if((vm.password!=vm.repassword)&&(vm.repassword.length>8||vm.repassword.length<20)){
							vm.tips="两次密码输入不一致";
							vm.colorStyle="color:red";
							vm.isRight=false;
						}else{
							vm.tips="";
							isRight=true;
						}
					},

				}
			})
		</script>
		
	</body>

</html>